package net.wanho.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.entity.User;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-03-22 9:58
 * Description：<描述>
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/users")
public class UserController {

    @ApiOperation("添加用户")
    @PostMapping
    public AjaxResult add(@RequestBody @ApiParam("用户信息") User user){
        return AjaxResult.success(user);
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable @ApiParam("用户编号") Integer id){
        return AjaxResult.success(id);
    }

    @ApiOperation("修改用户")
    @PutMapping
    public AjaxResult modify(@RequestBody User user){
        return AjaxResult.success(user);
    }

    @ApiIgnore
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Integer id){
        return AjaxResult.success(new User(id, "zhangsan", "123", 18, new Date()));
    }

    @ApiOperation("查询所有用户")
    @GetMapping
    public AjaxResult getAll(){
        List<User> list = new ArrayList();
        list.add(new User(1, "zhangsan", "123", 18, new Date()));
        list.add(new User(2, "lisi", "123", 18, new Date()));
        list.add(new User(3, "wangwu", "123", 18, new Date()));

        return AjaxResult.success(list);
    }
}
